package com.yafeng.config;

import com.yafeng.filter.Myfilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import sun.net.httpserver.AuthFilter;

@Configuration
public class MyFilterConfig {

    @Configuration
    public class FilterConfig {

        @Autowired
        private Myfilter myfilter;

        @Bean
        public FilterRegistrationBean registerAuthFilter() {
            FilterRegistrationBean registration = new FilterRegistrationBean();
            registration.setFilter(myfilter);
            registration.addUrlPatterns("/*");
            registration.addInitParameter("exclusions","/user-operator/login");

            registration.setOrder(1);  //值越小，Filter越靠前。
            return registration;
        }

        //如果有多个Filter，再写一个public FilterRegistrationBean registerOtherFilter(){...}即可。
    }
}
